package collectionday02exercise;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        list.add("one");
        System.out.println("list:"+list);//
        String s = list.get(2);
        System.out.println(s);//three

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("---------------");
        Iterator<String> it = list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

        System.out.println("------------");
        for (String o:list
             ) {
            System.out.println(o);
        }
        System.out.println("------------");

        String e = list.set(3,"seven");
        System.out.println(e);
        System.out.println(list);//[one, two, three, seven, five, one]

        list.add(3,"ten");
        System.out.println(list);//[one, two, three, ten,seven, five, one]
        String q = list.remove(3);
        System.out.println(q);//ten
        System.out.println(list);//[one, two, three, seven, five, one]



    }
}
